package com.ruoyi.async;

import java.util.concurrent.*;

public class Test {
    public static void main(String[] args) {
        new Test().handleResult("");
//        ExecutorService executor = Executors.newSingleThreadExecutor();
//        Future<String> future = executor.submit(new Callable<String>() {
//            @Override
//            public String call() throws Exception {
//                Thread.sleep(3000);
//                System.out.println("call");
//                // 耗时的操作
//                return "Result";
//            }
//        });
//
//        try {
//            String result = future.get(); // 这将阻塞，直到结果可用
//            System.out.println("dfdf");
//        } catch (InterruptedException | ExecutionException e) {
//            e.printStackTrace();
//        } finally {
//            executor.shutdown();
//        }
    }

    private void handleResult(String result) {
        try {
            CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
                // 这里执行你的异步操作
                try {
                    Thread.sleep(3000);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                System.out.println("dfsdf");
            });

            System.out.println("end");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
